/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package classPack;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;

/**
 *
 * @author Eu
 */
public class ClassesDAO {

//    private ClassesDAO secao = null;
//
//    private ClassesDAO() {
//    }
//
//    public ClassesDAO getInstance() {
//        if (secao == null) {
//            secao = new ClassesDAO();
//        }
//        return secao;
//    }
    public static void gravaObjectArquivo(Object classeGravar, String nome) {
        File arquivo = null;
        try {
            arquivo = new File("./" + nome + ".err");
            FileOutputStream fileOutput = new FileOutputStream(arquivo);
            BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutput);
            ObjectOutputStream objectOutput = new ObjectOutputStream(bufferedOutput);
            objectOutput.writeObject(classeGravar);
            objectOutput.flush();
        } catch (Exception e) {

        }
    }

    public static HashMap<String, Conversa> getConversaArquivo(String nomeClasse) {
        File arquivo = null;
        HashMap<String, Conversa> saida = new HashMap<String, Conversa>();
        try {
            arquivo = new File("./" + nomeClasse + ".err");
            FileInputStream fileInputStream = new FileInputStream(arquivo);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); //abre
            ObjectInputStream objetos = new ObjectInputStream(bufferedInputStream);
            saida = (HashMap<String, Conversa>) objetos.readObject();
        } catch (Exception e) {

        }
        return saida;
    }

    public static Usuario getUsuarioArquivo(String nomeClasse) {
        File arquivo = null;
        Usuario saida = null;
        try {
            arquivo = new File("./" + nomeClasse + ".err");
            FileInputStream fileInputStream = new FileInputStream(arquivo);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); //abre
            ObjectInputStream objetos = new ObjectInputStream(bufferedInputStream);
            saida = (Usuario) objetos.readObject();
        } catch (Exception e) {

        }
        return saida;
    }
}
